home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_all.zip / TI1202.ASC < prev    next >
Text File  |  1992-12-11  |  14KB  |  595 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  9.   VERSION  :  7.0
  10.        OS  :  All
  11.      DATE  :  December 11, 1992                        PAGE  :  1/9
  12.  
  13.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  14.  
  15.  
  16.  
  17.  
  18.  
  19.   VESA DRIVERS
  20.  
  21.        With the release of Borland Pascal for Objects 7.0,
  22.   programmers can now use BGI graphics to obtain 16 color
  23.   resolutions of 800 X 600, 1024 X 768, and 1280 X 1024.
  24.  
  25.   HOW TO USE THE VESA16.BGI DRIVER
  26.  
  27.        The VESA unit included with this Tech Info Sheet shows you a
  28.   simple way to use  the new VESA driver in your own program. To
  29.   get started, you need only include the word VESA in your uses
  30.   clause and then call the included Initialize procedure. So the
  31.   simplest possible program using the VESA driver might look like
  32.   this:
  33.  
  34.   program Simple;
  35.   uses
  36.      Graph,
  37.      Vesa;
  38.   begin
  39.     Initialize('c:\bp\bgi');
  40.     OutText('Hello');
  41.     ReadLn;
  42.     CloseGraph;
  43.   end.
  44.  
  45.  
  46.   This program assumes, of course, that you have the VESA unit
  47.   available on disk and that your BGI drivers are kept in the
  48.   C:\BP\BGI sub directory. If the system this program is run on
  49.   does not support the VESA BIOS then the code in the VESA unit
  50.   will automatically switch your computer into the highest
  51.   available mode.
  52.         The next few paragraphs describe a somewhat more complex
  53.   program, also included in this TI, which shows you how to use the
  54.   new high resolution modes. This program is called VesaSamp.Pas.
  55.   It uses the VESA unit, also listed below, to load the BGI  VESA
  56.   graphics driver into memory. The program then shows you the
  57.   highest available resolution on your system.
  58.        In order to simplify the process of entering graphics mode,
  59.   the VESA UNIT provides you with an easy to use Initialize
  60.   procedure which takes the location of the BGI drivers as its sole
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  75.   VERSION  :  7.0
  76.        OS  :  All
  77.      DATE  :  December 11, 1992                        PAGE  :  2/9
  78.  
  79.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  80.  
  81.  
  82.  
  83.  
  84.   parameter. This procedure will automatically switch you into
  85.   graphics mode, and also initialize several useful variables.
  86.        As presented below, program VesaSamp.Pas hardcodes the
  87.   location of the BGI drivers as being in the C:\BP\BGI sub
  88.   directory. If this is not the case on your system, then you need
  89.   to change this code before running the program. For instance, if
  90.   you store the BGI drivers in the D:\PASCAL\DRIVERS sub directory,
  91.   then you should change the call that reads:
  92.  
  93.   Initialize('c:\bp\bgi');
  94.  
  95.   so that it reads:
  96.  
  97.   Initialize('d:\pascal\drivers');
  98.  
  99.   If you have the BGI drivers available in the current sub
  100.   directory, then you would initialize the graphics system with the
  101.   following code:
  102.  
  103.   Initialize('');
  104.  
  105.   After correctly setting up the Initialize procedure, the VesaSamp
  106.   program will pop into graphics mode and show you the highest
  107.   available resolution.
  108.  
  109.   WHAT IS THE VESA BIOS?
  110.  
  111.        The VESA BIOS represents a standard for accessing SUPER VGA
  112.   resolutions. The problem it addresses is that there are many
  113.   different Super VGA boards on the market, but no common API for
  114.   addressing them.
  115.        To attempt to bring some sort of sanity to this madness, the
  116.   Video Electronics Standards Association (VESA) defined a set of
  117.   BIOS extensions that allow programmers to ask the video adapter
  118.   about its abilities. These BIOS extensions are sometimes
  119.   implemented directly in ROM and sometimes loaded into memory by a
  120.   special TSR. Many of these TSRs are available on the Compuserve
  121.   Information Service (1-800-848-8990).
  122.        Since it is always possible that the video card on any
  123.   particular system might not support the VESA extensions, you
  124.   should be aware that your program might not actually run in a
  125.   high resolution mode. But the Borland Graphics Interface will
  126.   find the highest available mode and then switch you into it.
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  141.   VERSION  :  7.0
  142.        OS  :  All
  143.      DATE  :  December 11, 1992                        PAGE  :  3/9
  144.  
  145.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  146.  
  147.  
  148.  
  149.  
  150.        The rest of this TI contains the sample code which shows you
  151.   how to use the VESA BGI driver. You should be aware of the fact
  152.   that it is necessary for the VESA .PAS unit to automatically
  153.   detect whether or not you have compiled your program as a
  154.   protected mode application. In other words, if you want to copy
  155.   code from the VESA unit directly into your program, make sure you
  156.   are getting the DOS code for DOS apps and the DPMI code for DPMI
  157.   apps.
  158.  
  159.   program VesaSamp;
  160.   {
  161.    A test program for unit Vesa
  162.    which provides Super VGA Resolutions
  163.   }
  164.   uses
  165.     Graph,
  166.     Vesa;
  167.  
  168.   { Converts an integer to a string }
  169.   function Int2Str(L : LongInt) : string;
  170.   var
  171.     S : string;
  172.   begin
  173.     Str(L, S);
  174.     Int2Str := S;
  175.   end; { Int2Str }
  176.  
  177.   var
  178.     S: String;
  179.   begin
  180.     Initialize('c:\bp\bgi');
  181.     Rectangle(0,0,MaxX,MaxY);
  182.     SetColor(LightGreen);
  183.     SetBkColor(Blue);
  184.     SetTextStyle(TriplexFont, HorizDir, 8);
  185.     S := 'MaxX = ' + Int2Str(MaxX);
  186.     OutTextXY((MaxX Div 2)  - (TextWidth(S) div 2),
  187.               (MaxY div 2) - 220, S);
  188.     S := 'MaxY = ' + Int2Str(MaxY);
  189.     OutTextXY((MaxX Div 2) - (TextWidth(S) div 2), (MaxY div 2) -
  190.   80, S);
  191.     S := 'MemAvail = ' + Int2Str(MemAvail);
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  207.   VERSION  :  7.0
  208.        OS  :  All
  209.      DATE  :  December 11, 1992                        PAGE  :  4/9
  210.  
  211.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  212.  
  213.  
  214.  
  215.  
  216.     OutTextXY((MaxX Div 2)  - (TextWidth(S) div 2), (MaxY div 2) +
  217.   60, S);
  218.     ReadLn;
  219.     CloseGraph;
  220.   end.
  221.  
  222.   {***************************************************}
  223.   {******************** VESA UNIT *********************}
  224.   {***************************************************}
  225.  
  226.   unit Vesa;
  227.   {
  228.           Add this unit to programs that want Vesa support
  229.     for high resolutions such as 800 X 600, 1024 X 768
  230.     and 1280 X 1024. If Vesa is not supported on a system
  231.     the code automatically defaults to an available driver
  232.     such as EGAVGA.
  233.          To Initialize the graphics system, just call
  234.     Initialize with the path to VESA.BGI as the sole
  235.     parameter. Pass an empty string if the driver
  236.     is in the current subdirectory.
  237.          The code will automatically detect if you are
  238.     running in protected mode or real mode.
  239.  
  240.     Examples:
  241.       Initialize('c:\bp\bin');
  242.       Initialize('');
  243.   }
  244.   Interface
  245.  
  246.   uses
  247.     Graph {$IfDef DPMI}, WinApi {$EndIf};
  248.  
  249.   const
  250.     VESA16Modes: array[0..2] of Word =
  251.       ($0102, $0104, $0106);
  252.  
  253.   type
  254.     VgaInfoBlock = record
  255.       VESASignature: array[0..3] of Byte;
  256.       VESAVersion: Word;
  257.       OEMStringPtr: Pointer;
  258.       Capabilities: array[0..3] of Byte;
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  273.   VERSION  :  7.0
  274.        OS  :  All
  275.      DATE  :  December 11, 1992                        PAGE  :  5/9
  276.  
  277.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  278.  
  279.  
  280.  
  281.  
  282.       VideoModePtr: Pointer;
  283.     end;
  284.  
  285.   var
  286.     MaxColor,
  287.     MaxX, MaxY: Integer;
  288.  
  289.   procedure Initialize(PathToDriver: String);
  290.   implementation
  291.  
  292.   var
  293.     VESA16      : Integer;  { Driver number of 16 color driver }
  294.  
  295.   function GetHighestCap(Table: Pointer; Modes: Word; Size:
  296.   Integer): Integer;
  297.     near; assembler;
  298.   asm
  299.           XOR     AX,AX
  300.           LES     DI, Table
  301.   @1:
  302.           MOV     SI, Modes
  303.           ADD     SI, Size
  304.           ADD     SI, Size
  305.           MOV     BX, ES:[DI]
  306.           CMP     BX, 0FFFFH
  307.           JE      @4
  308.           INC     DI
  309.           INC     DI
  310.           MOV     CX,Size
  311.   @2:
  312.           CMP     BX,[SI]
  313.           JZ      @3
  314.           DEC     SI
  315.           DEC     SI
  316.           LOOP    @2
  317.   @3:
  318.           CMP     AX,CX
  319.           JA      @1
  320.           MOV     AX,CX
  321.           JMP     @1
  322.   @4:
  323.   end;
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  339.   VERSION  :  7.0
  340.        OS  :  All
  341.      DATE  :  December 11, 1992                        PAGE  :  6/9
  342.  
  343.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  344.  
  345.  
  346.  
  347.  
  348.   {$IFDEF DPMI}
  349.   type
  350.     TRealRegs = record
  351.       RealEDI: Longint;
  352.       RealESI: Longint;
  353.       RealEBP: Longint;
  354.       Reserved: Longint;
  355.       RealEBX: Longint;
  356.       RealEDX: Longint;
  357.       RealECX: Longint;
  358.       RealEAX: Longint;
  359.       RealFlags: Word;
  360.       RealES: Word;
  361.       RealDS: Word;
  362.       RealFS: Word;
  363.       RealGS: Word;
  364.       RealIP: Word;
  365.       RealCS: Word;
  366.       RealSP: Word;
  367.       RealSS: Word;
  368.     end;
  369.  
  370.   function DetectVesa16: Integer; far; assembler;
  371.   var
  372.     Segment, Selector, VesaCap: Word;
  373.   asm
  374.   {$IFOPT G+}
  375.           PUSH    0000H
  376.           PUSH    0100H
  377.   {$ELSE}
  378.           XOR     AX,AX
  379.           PUSH    AX
  380.           INC     AH
  381.           PUSH    AX
  382.   {$ENDIF}
  383.           CALL    GlobalDosAlloc
  384.           MOV     Segment,DX
  385.           MOV     Selector,AX
  386.           MOV     DI,OFFSET RealModeRegs
  387.           MOV     WORD PTR [DI].TRealRegs.RealSP, 0
  388.           MOV     WORD PTR [DI].TRealRegs.RealSS, 0
  389.           MOV     WORD PTR [DI].TRealRegs.RealEAX, 4F00H
  390.           MOV     WORD PTR [DI].TRealRegs.RealES, DX
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  405.   VERSION  :  7.0
  406.        OS  :  All
  407.      DATE  :  December 11, 1992                        PAGE  :  7/9
  408.  
  409.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  410.  
  411.  
  412.  
  413.  
  414.           MOV     WORD PTR [DI].TRealRegs.RealEDI, 0
  415.           MOV     AX,DS
  416.           MOV     ES,AX
  417.           MOV     AX,0300H
  418.           MOV     BX,0010H
  419.           XOR     CX,CX
  420.           INT     31H
  421.           MOV     DI,OFFSET RealModeRegs
  422.           MOV     AX,grError
  423.           PUSH    AX
  424.           CMP     WORD PTR [DI].TRealRegs.RealEAX,004FH
  425.           JNZ     @Exit
  426.           POP     AX
  427.           MOV     ES,Selector
  428.           XOR     DI,DI
  429.           CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[0], 'EV'
  430.           JNZ     @Exit
  431.           CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[2], 'AS'
  432.           JNZ     @Exit
  433.           MOV     AX,0000
  434.           MOV     CX,1
  435.           INT     31H
  436.           MOV     VesaCap,AX
  437.           MOV     DX,ES:[DI].VgaInfoBlock.VideoModePtr.Word[2]
  438.           MOV     CX,4
  439.           XOR     AX,AX
  440.   @Convert:
  441.           SHL     DX,1
  442.           RCL     AX,1
  443.           LOOP    @Convert
  444.           ADD     DX,ES:[DI].VgaInfoBlock.VideoModePtr.Word[0]
  445.           ADC     AX,0
  446.           MOV     CX,AX
  447.           MOV     BX,VesaCap
  448.           MOV     AX,0007H
  449.           INT     31H
  450.           INC     AX
  451.           XOR     CX,CX
  452.           MOV     DX,0FFFFH
  453.           INT     31H
  454.           MOV     ES,BX
  455.           PUSH    ES
  456.           PUSH    DI
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  471.   VERSION  :  7.0
  472.        OS  :  All
  473.      DATE  :  December 11, 1992                        PAGE  :  8/9
  474.  
  475.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  476.  
  477.  
  478.  
  479.  
  480.   {$IFOPT G+}
  481.           PUSH    OFFSET Vesa16Modes
  482.           PUSH    0003H
  483.   {$ELSE}
  484.           MOV     SI, OFFSET Vesa16Modes
  485.           PUSH    SI
  486.           MOV     AX, 5
  487.           PUSH    AX
  488.   {$ENDIF}
  489.           CALL    GetHighestCap
  490.           PUSH    AX
  491.           MOV     BX,VesaCap
  492.           MOV     AX,0001H
  493.           INT     31H
  494.   @Exit:
  495.           PUSH    Selector
  496.           CALL    GlobalDosFree
  497.           POP     AX
  498.   end;
  499.   {$ELSE}
  500.   function DetectVesa16: Integer; far; assembler;
  501.   var
  502.     VesaInfo: array[0..255] of Byte;
  503.   asm
  504.           MOV     AX,SS
  505.           MOV     ES,AX
  506.           LEA     DI,VesaInfo
  507.           MOV     AX,4F00H
  508.           INT     10H
  509.           CMP     AX,004FH
  510.           MOV     AX,grError
  511.           JNZ     @Exit
  512.           CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[0], 'EV'
  513.           JNZ     @Exit
  514.           CMP     ES:[DI].VgaInfoBlock.VESASignature.Word[2], 'AS'
  515.           JNZ     @Exit
  516.           LES     DI,ES:[DI].VgaInfoBlock.VideoModePtr
  517.           PUSH    ES
  518.           PUSH    DI
  519.           MOV     AX, OFFSET Vesa16Modes
  520.           PUSH    AX
  521.           MOV     AX,3
  522.           PUSH    AX
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.   PRODUCT  :  Borland Pascal/Turbo Pascal           NUMBER  :  1202
  537.   VERSION  :  7.0
  538.        OS  :  All
  539.      DATE  :  December 11, 1992                        PAGE  :  9/9
  540.  
  541.     TITLE  :  Using the VESA16.BGI that Comes with BP 7.0
  542.  
  543.  
  544.  
  545.  
  546.           CALL    GetHighestCap
  547.   @Exit:
  548.   end;
  549.   {$ENDIF}
  550.  
  551.   procedure Initialize(PathToDriver: String);
  552.   var
  553.     MaxColor,
  554.     ErrorCode,
  555.     GraphMode,
  556.     GraphDriver: Integer;
  557.   begin
  558.     VESA16 := InstallUserDriver('VESA16', @DetectVESA16);
  559.     GraphDriver := Detect;
  560.     InitGraph(GraphDriver, GraphMode, PathToDriver);
  561.     ErrorCode := GraphResult;
  562.     if ErrorCode <> grOK then begin
  563.       WriteLn('Graphics error: ', GraphErrorMsg(ErrorCode));
  564.       ReadLn;
  565.       Halt;
  566.     end;
  567.     MaxX := GetMaxX;
  568.     MaxY := GetMaxY;
  569.     MaxColor := GetMaxColor;
  570.   end;
  571.   end.
  572.  
  573.  
  574.   DISCLAIMER: You have the right to use this technical information
  575.   subject to the terms of the No-Nonsense License Statement that
  576.   you received with the Borland product to which this information
  577.   pertains.
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.